package com.zzyl.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.dto.RoleDto;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.RoleVo;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;



    @PutMapping
    @ApiOperation(value = "用户增加")
    public ResponseResult<UserVo>  AddUser(@RequestBody UserDto userDto) {
        log.info("添加的数据：{}", userDto);
       Boolean   flag1  = userService.AddUser(userDto);
        return ResponseResult.success(flag1);
    }

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户分页")
    public ResponseResult<PageResponse<UserVo>> findUserVoPageResponse(
            @RequestBody UserDto userDto, @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize) {
        
        PageResponse<UserVo> pageResponse = userService.finduserPage(userDto, pageNum, pageSize);
      log.info("分页查询的数据：{}", pageResponse);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 删除部门
     */
    @ApiOperation("删除用户")
    @DeleteMapping("/remove/{userIds}")
    public ResponseResult remove(@PathVariable String userIds) {

        log.info("删除用户:{}", userIds);
        userService.deleteUseById(userIds);
       return ResponseResult.success();
    }
//用户的启用禁用
    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation(value = "启用-禁用",notes = "启用-禁用")
    @ApiOperationSupport(includeParameters = {"userDto.userState","userDto.id"})
    public ResponseResult isEnable(@PathVariable(name = "id") Long id,@PathVariable(name = "status")String status){

     userService.isEnuser(id,status);
      return ResponseResult.success();
    }

}
